package club.zhcs.capture.biz.auth.impl;

import java.util.List;

import club.zhcs.capture.bean.auth.RolePermission;
import club.zhcs.capture.biz.auth.IRolePermissionService;
import club.zhcs.capture.dao.IRolePermissionDao;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.entity.Record;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import com.dgj.utils.db.SqlActuator;

@IocBean(name = "rolePermissionService")
public class RolePermissionService implements IRolePermissionService {
	@Inject
	IRolePermissionDao rolePermissionDao;
	@Inject
	private PropertiesProxy sqls;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.dgj.boss.service.auth.IRolePermissionService#findByPermissionId(int)
	 */
	@Override
	public List<RolePermission> findByPermissionId(int id) {
		return rolePermissionDao.search(Cnd.where("permissionId", "=", id));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.dgj.boss.service.auth.IRolePermissionService#findByRoleId(int)
	 */
	@Override
	public List<Record> findByRoleId(int id) {
		final Dao dao = rolePermissionDao.getDao();
		Sql sql = Sqls.create(sqls.get("find.role.permission.by.role.id"));
		sql.params().set("roleId", id);
		return SqlActuator.runReport(sql, dao);
	}

}
